define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'air/custom/index' + location.search,
                    add_url: 'air/custom/add',
                    edit_url: 'air/custom/edit',
                    // del_url: 'air/custom/del',
                    multi_url: 'air/custom/multi',
                    import_url: 'air/custom/import',
                    table: 'air_custom',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'travel_type', title: __('Travel_type'), searchList: {"1":__('Travel_type 1'),"2":__('Travel_type 2'),"3":__('Travel_type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'price_budget', title: __('价格预算'),
                          formatter: function(value, row, index) {
                            return '低于' + value + '万元';
                          }
                        },
                        {field: 'flex_date', title: __('Flex_date'), 
                          formatter: function(value, row, index) {
                            if (value == '1') {
                                return '±3日'
                            }
                            if (value == '2') {
                                return '±7日'
                            }
                            if (value == '3') {
                                return '±7日'
                            }
                          }
                        },
                        {field: 'plane_like', title: __('Plane_like'),
                          formatter: function(value, row, index) {
                            if (value == '1') {
                                return '不限'
                            }
                            if (value == '2') {
                                return '小型飞机'
                            }
                            if (value == '3') {
                                return '中大型飞机'
                            }
                            if (value == '4') {
                                return '超远程飞机'
                            }
                            if (value == '5') {
                                return '超大型飞机'
                            }
                          }
                        },
                        {field: 'person_total', title: __('Person_total')},
                        {field: 'contactor', title: __('Contactor'), operate: 'LIKE'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'handle_status', title: __('跟进状态'), operate: 'LIKE',
                          formatter: function(value, row, index) {
                            if (value == '0') {
                                return '已取消'
                            }
                            if (value == '1') {
                                return '跟进中'
                            }
                            if (value == '2') {
                                return '已发方案'
                            }
                          }
                        },
                        {field: 'note', title: __('Note'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {   
                          field: 'operate', 
                          title: __('Operate'), 
                          table: table, 
                          events: Table.api.events.operate, 
                          buttons: [
                              {   
                                  name: 'planyear',
                                  text: __('查看行程'),
                                  icon: 'fa',
                                  classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                  url: function (row) {
                                      return Fast.api.fixurl('air/custom_travel/index?cid=' + row.id)
                                  },
                              },  
                          ],  

                          formatter: Table.api.formatter.operate

                        } 
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
